// 新增其他情况组件


// 新增研发饱和度指标组件


// 新增团队情况组件


import React, { Component } from 'react';
import NetUitl from '../utils/HttpUtil';
import {Input, message, Table} from "antd";
import TitleBar from "./TitleBar";
import "./add.scss";


class AddOther extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataSource:[
                {
                    moduleNum:"",
                    supportProjectNum:"",
                    companyOfficeNum:"",
                    homeOfficeNum:"",
                    clientOfficeNum:"",
                    vacationNum:"",
                    minerNum:""
                }
            ]
        }

        this.columns=[
            {
                title: '在研模块数',
                dataIndex: 'moduleNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.moduleNum} onChange={this.moduleChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '支持项目数',
                dataIndex: 'supportProjectNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.supportProjectNum} onChange={this.projectChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '公司办公人数',
                dataIndex: 'companyOfficeNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.companyOfficeNum} onChange={this.peopleChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '居家办公人数',
                dataIndex: 'homeOfficeNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.homeOfficeNum}  onChange={this.homeChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '客户现场人数',
                dataIndex: 'clientOfficeNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.clientOfficeNum}   onChange={this.sceneChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '休假人数',
                dataIndex: 'vacationNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.vacationNum}  onChange={this.holidayChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            },
            {
                title: '旷工人数',
                dataIndex: 'minerNum',
                width:"14.25%",
                render: (text,record)=>{
                    if (this.props.isAdd === true){
                        return <Input placeholder={"必填：数字"} value={record.minerNum}  onChange={this.absenteeChange}></Input>
                    }else{
                        return <span>{text}</span>
                    }
                }
            }
        ]
    }

    componentDidMount(){
        let dataSource=[];
        dataSource.push(this.props.allData.other);
        this.setState({dataSource})
    }
    componentWillReceiveProps(nextprops){
        let dataSource=[];
        dataSource.push(nextprops.allData.other);
        this.setState({dataSource})
    }

    //在研模块数change事件
    moduleChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].moduleNum = e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //支持项目数change事件
    projectChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].supportProjectNum =  e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //公司办公人数change事件
    peopleChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].companyOfficeNum =  e.target.value;
        console.log(dataSource,"peopleChange")
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //居家办公人数change事件
    homeChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].homeOfficeNum =  e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //客户现场人数change事件
    sceneChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].clientOfficeNum =  e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //休假人数change事件
    holidayChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].vacationNum =  e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    //旷工人数change事件
    absenteeChange=(e)=>{
        var re =  /^(0|\+?[1-9][0-9]*)$/;
        if (e.target.value !== ""){
            if (!re.test( e.target.value)) {
                return  message.warning("请输入正整数！");
            }
        }

        let {dataSource} = this.state;
        dataSource[0].minerNum =  e.target.value;
        this.setState({dataSource});

        // let allData={};
        // allData.other = dataSource[0];
        // this.props.viewer.setState({allData})
    }

    render() {
        const isAdd = this.props.isAdd;

        return (
            <div className="addOther-box">
                <div className={"addOther-top"}>
                    <div>
                        <TitleBar name={"其他情况"}></TitleBar>
                    </div>
                </div>
                <div className={"addOther-main"}>
                    <Table
                        className={"addOther-table"}
                        bordered
                        columns={this.columns}
                        dataSource={this.state.dataSource}
                        pagination={false}
                    />
                </div>
            </div>
        );
    }
}

export default  AddOther;
